{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9ddc752c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'python'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr = 'python'\n",
    "pystr[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c1501dcd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'thon'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5e0a8d08",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'py'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "390a5474",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'yt'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e9fd8dd1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'pt'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[0:4:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d7176bed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'hon'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[-3:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ca10be7",
   "metadata": {},
   "source": [
    "从倒数第五到倒数第三（不取倒数第三）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ec34a486",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'yt'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[-5:-3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e960f160",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[-3:-5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e9b5cfb7",
   "metadata": {},
   "source": [
    "将字符串倒序，步长为1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "07488b37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'nohtyp'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[::-1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0c205ed0",
   "metadata": {},
   "source": [
    "将字符串倒序，步长为2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5e6dbb8a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'nhy'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[::-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a4dceb60",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ht'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[-3:-5:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f6d57184",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ho'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[3:5:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "44e41210",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pystr[-5:-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "57ff1e09",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval(\"5+10\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4701f0c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval(\"10 if 4<5 else 7\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2063c8bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval(\"10 if 4>5 else 7\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d0858bc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "my_test",
   "language": "python",
   "name": "my_test"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
